<template>
  <van-cell-group inset>
    <van-field v-model="digit" type="digit" label="账号" />
    <van-field v-model="password" type="password" label="密码" />
  </van-cell-group>
  <div class="button-container">
    <van-button type="success" @click="zc">登录</van-button>
  </div>
</template>

<script setup>
import { ref } from 'vue'
// import axios from 'axios'
import axios from '../xyq.js'
import { useRouter } from 'vue-router'
const router = useRouter()

const digit = ref('')
const password = ref('')

let zc = () => {
  axios
    .post(
      'http://localhost:8888/users/login',
      {
        password: password.value,
        username: digit.value,
      },
      {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded',
        },
      },
    )
    .then(res => {
      console.log(res.data)
      localStorage.setItem('token', res.data.token)
      localStorage.setItem('user', res.data.user.id)
      router.push('/my')
    })
}
</script>

<style scoped>
.button-container {
  display: flex;
  justify-content: center;
  margin-top: 20px; /* 可以根据需要调整间距 */
}
</style>
